<?php
/*
 * Created on Sep 10, 2010
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */

class Response {

	public function send404() 
	{
		header("HTTP/1.1 404 Not Found");
		exit;
	}
	
	public function redirect($location) 
	{
		Header('Location: ' . $location);
	}
		
	public function setCookie($name, $value) 
	{
		
	}
		
	public function transmitFile($file) 
	{
	    if (!is_file($file)) { 
	    	$this->send404();
	    }
	
	   	$length = filesize($file);
	   	$filename = basename($file);
	   	$fileExtension = strtolower(substr(strrchr($filename, "."), 1));

		$map = array();
	    
		$map["pdf"] = "application/pdf"; 
		$map["exe"] = "application/octet-stream";
		$map["zip"] = "application/zip";
		$map["doc"] = "application/msword"; 
		$map["xls"] = "application/vnd.ms-excel";
		$map["ppt"] = "application/vnd.ms-powerpoint"; 
		$map["gif"] = "image/gif";
		$map["png"] = "image/png"; 
		$map["jpeg"] = "image/jpg";
		$map["jpg"] = "image/jpg";
		$map["mp3"] = "audio/mpeg"; 
		$map["wav"] = "audio/x-wav"; 
		$map["mpeg"] = "video/mpeg"; 
		$map["mpg"] = "video/mpeg";
		$map["mpe"] = "video/mpeg"; 
		$map["mov"] = "video/quicktime"; 
		$map["avi"] = "video/x-msvideo"; 
	   
		header("Content-Description: File Transfer");	    
		header("Content-Type: application/force-download");
		header("Content-Disposition: attachment; filename=". $filename . ";");
		header("Content-Length: ". $length);
	    
		@readfile($file);
	    
	   exit;
	}	
}

?>
